<?php namespace App\Core\Service;

use App\Http\Controllers\Controller;

abstract class Listener {
    
    protected $name = '';
    protected $service = null;

    public function boot(Controller $service){
        $this->service = $service;
    }

    public function fire($event){
        $eventMethod = 'on'.ucfirst($event);
        if(method_exists($this, $eventMethod)){
            $args = array_slice(func_get_args(), 1);
            call_user_func_array([$this, $eventMethod], $args);
        }
    }
    
    public function getName(){
        return $this->name ? $this->name : static::class;
    }
    
    public function setName($name){
        $this->name = $name;
    }
}
